#include "StdAfx.h"
#include "util.h"

using namespace SocketCtrl;

bool SocketCtrl::splitSockAddr(const sockaddr &addr, std::string &ip, int &port)
{
	const sockaddr_in *addrIn = (const sockaddr_in *)&addr;

	port = ntohs(addrIn->sin_port);
	ip = ::inet_ntoa(addrIn->sin_addr);

	return true;
}

bool SocketCtrl::fillSockAddr(sockaddr &addr, const std::string &ip, int port)
{
	::ZeroMemory(&addr, sizeof(addr));

	sockaddr_in *addrIn = (sockaddr_in *)&addr;

	addrIn->sin_family = AF_INET;
	addrIn->sin_port = htons(port);
	addrIn->sin_addr.S_un.S_addr = ::inet_addr(ip.c_str());

	return true;
}